// src/core/router-types.ts

import type { ModuleId } from './types';
import { RouteRecordRaw } from 'vue-router';

/**
 * 增强的路由记录
 */
export interface ModuleRouteRecord extends RouteRecordRaw {
  meta?: ModuleRouteMeta;
  children?: ModuleRouteRecord[];
}

/**
 * 支持模块元信息的路由配置
 */
export function defineModuleRoutes(
  moduleId: ModuleId,
  routes: ModuleRouteRecord | ModuleRouteRecord[]
): ModuleRouteRecord[] {
  const normalized = Array.isArray(routes) ? routes : [routes];
  
  return normalized.map(route => ({
    ...route,
    meta: {
      ...(route.meta || {}),
      moduleId
    }
  }));
}

/**
 * 模块视图组件接口
 */
export interface ModuleViewComponent {
  setup(props: any, ctx: { 
    state: Record<string, any> 
  }): RenderFunction;
  
  beforeRouteEnter?(
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: NavigationGuardNext
  ): void;
  
  moduleId?: ModuleId;
}